import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../AppConfig/Config.dart';
import '../AddGoodsFirst.dart';

class AddCarrierVehicles extends StatefulWidget {
  const AddCarrierVehicles({super.key});

  @override
  State<AddCarrierVehicles> createState() => _AddCarrierVehiclesState();
}

class _AddCarrierVehiclesState extends State<AddCarrierVehicles> {
  String vehicleNum="";
  List carLength=[];
  List carType=[];
  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        leading: IconButton(icon: Icon(Icons.arrow_back_ios,color: Colors.black,),onPressed: (){Navigator.pop(context);},),
        centerTitle: true,
        backgroundColor: Colors.white,
        title: Text("新增承运车辆",style: TextStyle(color: Colors.black,fontSize: 16.sp,fontWeight: FontWeight.w300),),
      ),
      body: ListView(
        children: [
          Container(
            margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
            padding: EdgeInsets.only(left: 10.w,top: 10.h,right: 10.w,bottom: 10.h),
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10))),
            child: Column(
              children: [
                GestureDetector(
                  child:   Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("*",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),),
                          Text("车牌号",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                        ],

                      ),
                      Row(
                        children: [
                          vehicleNum==""?
                          Text("请选择",style: TextStyle(color: MyColors.hintColor,fontSize: 14.sp),):
                          Text(vehicleNum,style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                          Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.authTipColor,),
                        ],

                      ),
                    ],
                  ),
                  onTap: ()async{
                    String textValue="";
                  final result=await  showModalBottomSheet(context: context,
                        // isScrollControlled:true,
                        builder: (BuildContext context)
                        {
                          return  Container(
                          padding: EdgeInsets.only(left: 10.w,right: 10.w,top: 10.h),
                            decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.all(Radius.circular(10))),
                            child: Column(
                              children: [
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  children: [
                                    TextButton(onPressed: (){Navigator.pop(context);}, child: Text("取消",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),)),
                                    Text("车牌号码",style: TextStyle(color: Colors.black,fontSize: 16.sp,fontWeight: FontWeight.w600),),
                                    TextButton(onPressed: (){Navigator.pop(context,textValue);}, child: Text("确定",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),)),
                                  ],
                                ),
                                SizedBox(height: 10.h,),
                                Container(
                                  width: screenSize.width-30.w,
                                  height: 35.h,
                                  child:  Center(
                                    child:  TextField(
                                      decoration: InputDecoration(
                                        hintText:  '请输入车牌号码',
                                        hintStyle:TextStyle(fontSize: 14.sp,color: MyColors.hintColor),
                                        filled: true,
                                        fillColor: MyColors.backgreyColor,
                                        border: InputBorder.none,
                                        alignLabelWithHint: true,

                                      ),
                                      keyboardType: TextInputType.number,
                                      textAlign: TextAlign.left,
                                      style: TextStyle(color: Colors.black),
                                      onChanged: (value) {
                                        setState(() {
                                          print(value);
                                          textValue=value;
                                        });
                                      },
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          );
                        }
                        );
                  if(result!=null){
                    setState(() {
                      vehicleNum=textValue;
                    });

                  }
                  },
                ),
                Divider(height: 16.h,color: MyColors.backgreyColor,),
                GestureDetector(
                  child:   Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text("*",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),),
                          Text("车长车型",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                        ],

                      ),
                      Row(
                        children: [
                          !carLength.isEmpty&&!carType.isEmpty?
                          Text(carLength.map((element) => '$element米').join(', ').replaceAll(" ", "")+"\n"+carType.join(', ').replaceAll(" ", ""),style: TextStyle(color: Colors.black,fontSize: 14.sp),):
                          Text("请选择",style: TextStyle(color: MyColors.hintColor,fontSize: 14.sp),),
                          Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.authTipColor,),
                        ],

                      ),
                    ],
                  ),
                  onTap: ()async{
                    final result = await  showModalBottomSheet(context: context,
                        isScrollControlled:true,
                        isDismissible: false, // 设置为 false，点击外部区域不关闭
                        enableDrag: false, // 设置为 false，禁用上滑手势关闭
                        builder: (BuildContext context)
                        {
                          return  carLengthandTypeSheet(carLength: carLength, carType: carType,);
                        });
                    if (result != null) {
                      setState(() {
                        carLength = result[0];
                        carType=result[1];
                      });
                    }
                  },
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
}
